package com.me.mygdxgame.models;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.me.mygdxgame.assets.Assets;

public class Stone extends AbstractGameObject{

	public enum TYPE{
		ONE,
		TWO,
		THREE
	}
	private TYPE type;
	private Texture texStone;
	private TextureRegion regStone;
	public boolean collected;
	private TextureRegion[] stoneFrames;
	private TextureRegion[] temp;
	private float stateTime = 0;
	private Animation stoneAnimation;

	public Stone(TYPE type){
		init(type);
	}
	
	private void init(TYPE type) {
		switch (type) {
		case ONE:
			texStone = Assets.stone1;
			break;
		case TWO:
			texStone = Assets.stone2;
			break;
		case THREE:
			texStone = Assets.stone3;
			break;
		}
//		regStone = new TextureRegion(texStone, 0, 0, 40, 53);
//		sprite.setRegion(regStone);
		temp = TextureRegion.split(texStone, 40, 53)[0];
		stoneFrames = getTextures(1, 5, temp);
		stoneAnimation = new Animation(0.2f, stoneFrames);
//		dimension.set(40, 53f);
		sprite.setSize(40, 53);
//		bounds.set(0, 0, dimension.x, dimension.y);
		collected = false;
	}
	
	@Override
	public void render(SpriteBatch batch) {
		if(collected)return;
//		TextureRegion reg = null;
//		reg = regStone;
//		batch.draw(reg.getTexture(),
//				position.x, position.y,
//				origin.x, origin.y,
//				dimension.x, dimension.y,
//				scale.x, scale.y,
//				rotation,
//				reg.getRegionX(), reg.getRegionY(),
//				reg.getRegionWidth(), reg.getRegionHeight(), 
//				false, false
//				);
		sprite.setRegion(stoneAnimation.getKeyFrame(stateTime, true));
		sprite.draw(batch);
	}

	@Override
	public void update(float deltaTime) {
		super.update(deltaTime);
		stateTime += deltaTime;
	}

}
